package com.ecnu.ob.test;

import java.util.Map;

import org.junit.Assert;

import com.alibaba.middleware.race.rpc.api.RpcConsumer;
import com.alibaba.middleware.race.rpc.api.impl.RpcConsumerImpl;
import com.alibaba.middleware.race.rpc.demo.service.RaceConsumerHook;
import com.alibaba.middleware.race.rpc.demo.service.RaceDO;
import com.alibaba.middleware.race.rpc.demo.service.RaceServiceListener;
import com.alibaba.middleware.race.rpc.demo.service.RaceTestService;
import com.alibaba.middleware.race.rpc.model.RpcResponse;

public class test {
	public static void main(String[] args) {
		
//		RpcConsumer consumer=new RpcConsumerImpl();
//		IHello hl=(IHello) consumer
//                .interfaceClass(IHello.class)
//                .version("1.0.0.api")
//                .clientTimeout(3000)
//                .instance();
//		
//		for (int i = 0; i < 10000; i++) {
//			String s=hl.sayHello("zhujun"+i);
//			System.out.println(s);
//		}
		RpcConsumer consumer = new RpcConsumerImpl();
		RaceTestService apiService = (RaceTestService) consumer
                .interfaceClass(RaceTestService.class)
                .version("1.0.0.api")
                .clientTimeout(3000)
                .hook(null).instance();
		
		
//		RaceServiceListener listener = new RaceServiceListener();
//        consumer.asynCall("getDO", listener);
//        RaceDO nullDo = apiService.getDO();
//        Assert.assertEquals(null, nullDo);
//        try {
//        	 RaceDO resultDo = (RaceDO) listener.getResponse();
//        } catch (InterruptedException e) {
//        	e.printStackTrace();
//        }
//        
//        apiService.getMap();
        String s= apiService.getString();
        System.out.println(s);
        
		
		//apiService.getDO();
		System.out.println("ok");
		
//		RpcConsumer consumer=new RpcConsumerImpl();
//		IHello hl=(IHello) consumer
//                .interfaceClass(IHello.class)
//                .version("1.0.0.api")
//                .clientTimeout(3000)
//                .instance();
//		
//		for (int i = 0; i < 10000; i++) {
//			String s=hl.sayHello("zhujun"+i);
//			System.out.println(s);
//		}
		/*
		TestRaceListener listener=new TestRaceListener();
		
		consumer.asynCall("sayHello",listener);
		
		String s=hl.sayHello("zhujun");
		System.out.println(s);
		
		try {
            RpcResponse ret = (RpcResponse) listener.getResponse();
            System.out.println(ret.getResult());
        } catch (Exception e) {
        	e.printStackTrace();
        }
        */
		
		/*
		RpcConsumer consumer=new RpcConsumerImpl();
		final RaceTestService apiService = (RaceTestService) consumer
                .interfaceClass(RaceTestService.class)
                .version("1.0.0.api")
                .clientTimeout(3000)
                .hook(new RaceConsumerHook()).instance();
		
		TestRaceListener listener=new TestRaceListener();
		
		//consumer.asynCall("getString", listener);
		
		Thread t1=new Thread(new Runnable() {
			
			@Override
			public void run() {
				while(true)
				{
				// TODO Auto-generated method stub
				RaceDO do1=apiService.getDO();
				if(do1==null)
					System.out.println(Thread.currentThread().getId()+"--null");
				else
					System.out.println(Thread.currentThread().getId()+"ok");
				}
				
			}
		});
		Thread t2=new Thread(new Runnable() {
			
			@Override
			public void run() {
				// TODO Auto-generated method stub
				while(true)
				{
				RaceDO do2=apiService.getDO();
				if(do2==null)
					System.out.println(Thread.currentThread().getId()+"--null");
				else
					System.out.println(Thread.currentThread().getId()+"ok");
				}
				
			}
		});
		t1.start();
		t2.start();
		try {
			t1.join();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		try {
			t2.join();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		*/
//		String s= apiService.getString();
//		System.out.println(s);
//		
//		try {
//			
//			RpcResponse ret = (RpcResponse) listener.getResponse();
//			System.out.println(ret.getResult());
//			
//		} catch (Exception e) {
//			// TODO: handle exception
//		}
		
		
	}
}
